package org.uoss.webapp.framework.struts2.security.intercept;

import org.apache.struts2.ServletActionContext;
import org.springframework.web.util.UrlPathHelper;
import org.uoss.webapp.framework.http.HttpUtil;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class AccessingPermissionInterceptor extends AbstractInterceptor   {
	private static final long serialVersionUID = -3540473276979791286L;
	private UrlPathHelper urlPathHelper = new UrlPathHelper();
	
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		String jspurl = urlPathHelper.getLookupPathForRequest(ServletActionContext.getRequest());
		if(jspurl.endsWith("logon.action")){
			return invocation.invoke();
		}
		Object userobject = HttpUtil.getHttpSession().getAttribute("USER_SESSION_KEY");
		if(userobject!=null){
			return invocation.invoke();
		}
		return Action.LOGIN;
	}
}
